package com.action.tree.bean;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.dao.DataOperations;
import com.dbtools.Dispose;
import com.exception.SelectException;
import com.action.tree.TreeInfo;
import com.action.tree.TreeOperation;

public class MorgTree extends DataOperations implements TreeOperation{
	public MorgTree() {
		super();
	}
	public MorgTree(Connection connection) {
		super(connection);
	}
    
	public List select(Object obj) throws SelectException{
		List list=new ArrayList();
		StringBuffer sql = new StringBuffer();
		sql.append(" SELECT a.ORGID as ORGID,a.CODE as CODE,a.NAME as NAME,a.PARENTID as PARENTID, ");
		sql.append(" a.ISDEL as ISDEL,SEQ=(SELECT COUNT(DISTINCT PARENTID) FROM T_S_ORG WHERE PARENTID<=a.PARENTID) "); 
		sql.append(" FROM T_S_ORG a ORDER BY SEQ ");
    	ResultSet rest=null;
		try {
			System.out.println("select is  "+sql);
		   rest = super.executeQuery(sql.toString());
		   while(rest.next()){
			 TreeInfo info=new TreeInfo();
			 info.setId(rest.getString("ORGID"));
			 info.setParentId(rest.getString("PARENTID"));
			 info.setText("(" + rest.getString("CODE") + ")"+ rest.getString("NAME").trim());
			 list.add(info);
			}
		} catch (SQLException e) {
			throw new SelectException(e.getMessage());
		} finally {
			Dispose.dispose(rest);
		}
		return list;
	}
	public boolean delete(Object obj) {
		return false;
	}
	public boolean insert(Object obj) {
		return false;
	}
	public boolean update(Object obj) {
		return false;
	}

}
